//
//  M1CertificationVC.m
//  NewMarryU
//
//  Created by Cedar on 2018/7/19.
//  Copyright © 2018年 Cedar. All rights reserved.
//

#import "M1CertificationVC.h"

@interface M1CertificationVC ()

@property (nonatomic, strong) UIImageView *m1_icon;

@property (nonatomic, strong) UIView *m1_certificationView_no;

@property (nonatomic, strong) UIView *m1_certificationView;

@end

@implementation M1CertificationVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = self.m1_title;

    UIImageView *bgImage = [[UIImageView alloc] initWithFrame:self.view.bounds];
    [bgImage setImage:LOAD_LOCAL_IMG(@"personal_image_cerBgView")];
    bgImage.contentMode = UIViewContentModeScaleAspectFill;
    bgImage.clipsToBounds = YES;
    [self.view addSubview:bgImage];
    
    [self m1_createUI];
    
}

- (void)m1_cerAction:(UIButton *)sender{
    NSString *page = @[@"", @"M1CertifyEducationVC", @"M1CertifyHouseVC", @"M1CertifyCarVC"][self.m1_type];
    NSString *title = @[@"", @"学历信息", @"房产信息", @"汽车信息"][self.m1_type];
    UIViewController *vc = [[NSClassFromString(page) alloc] init];
    vc.title = title;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)m1_createUI{
    
    self.m1_icon = [[UIImageView alloc] init];
    [self.view addSubview:_m1_icon];
    
    CGFloat height = m1_NAV_HEIGHT + (iPhone5?15:80);
    [_m1_icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.mas_centerX);
        make.top.offset(height);
        make.size.mas_equalTo(CGSizeMake(100, 100));
    }];
    
    NSString *imageStr;
    
    if ((self.m1_type == 0 && [M1User user].basic.identity_info.identity_auth.auth_status == 1) || (self.m1_type == 1 && [M1User user].basic.education_info.education_auth.auth_status == 1) || (self.m1_type == 2 && [M1User user].basic.house_info.house_auth.auth_status == 1) || (self.m1_type == 3 && [M1User user].basic.car_info.car_auth.auth_status == 1)) {
    
        imageStr = @[@"personal_cer_idcard", @"personal_cer_education", @"personal_cer_house", @"personal_cer_cars"][self.m1_type];
        [self m1_cerView];
    }else{
        imageStr = @[@"", @"personal_cer_education_no", @"personal_cer_house_no", @"personal_cer_cars_no"][self.m1_type];
        [self m1_cerView_no];

    }
    _m1_icon.image = LOAD_LOCAL_IMG(imageStr);
}

- (void)m1_cerView_no{
    self.m1_certificationView_no = [[UIView alloc] init];
    [self.view addSubview:_m1_certificationView_no];
    
    [_m1_certificationView_no mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.m1_icon.mas_bottom).offset(45);
        make.centerX.equalTo(self.view.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(SCREENWIDTH, 325));
    }];
    
    UILabel *title = [[UILabel alloc] init];
    title.text = @[@"", @"博学多才", @"斯是陋室", @"您的座驾"][self.m1_type];
    title.textColor = m1_color(0xFFFFFF);
    title.font = m1_font(25);
    [_m1_certificationView_no addSubview:title];
    
    [title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);
        make.centerX.equalTo(self.m1_certificationView_no.mas_centerX);
    }];
    
    UILabel *label = [[UILabel alloc] init];
    label.text = @[@"", @"为什么要完善学历信息？", @"为什么要完善房产信息？", @"为什么要完善汽车信息？"][self.m1_type];
    label.textColor = m1_color(0x808080);
    label.font = m1_font(16);
    [_m1_certificationView_no addSubview:label];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(title.mas_bottom).offset(15);
        make.centerX.equalTo(self.m1_certificationView_no.mas_centerX);
    }];
    
    UILabel *content = [[UILabel alloc] init];
    content.text = @"1、点亮信息勋章，魅力值提升2倍\n2、提高自身价值，更容易获得青睐；\n3、完善信息的用户，更容易获得推荐，更多曝光机会。";
    content.textColor = m1_color(0x808080);
    content.font = m1_font(15);
    content.numberOfLines = 0;
    [_m1_certificationView_no addSubview:content];
    
    [content mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(label.mas_bottom).offset(37);
        make.left.offset(47);
        make.right.offset(-47);
    }];
    
    
    UIButton *cerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    cerBtn.backgroundColor = m1_color(0xDBB76B);
    [cerBtn setTitle:@"立即认证" forState:UIControlStateNormal];
    [cerBtn setTitleColor:m1_color(0xFFFFFF) forState:UIControlStateNormal];
    [cerBtn addTarget:self action:@selector(m1_cerAction:) forControlEvents:UIControlEventTouchUpInside];
    cerBtn.tag = 1;
    [_m1_certificationView_no addSubview:cerBtn];
    
    cerBtn.layer.cornerRadius = 45 / 2;
    cerBtn.layer.masksToBounds = YES;
    
    [cerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.m1_certificationView_no.mas_centerX);
        make.bottom.offset(0);
        make.size.mas_equalTo(CGSizeMake(200, 45));
    }];
}

- (void)m1_cerView{
    self.m1_certificationView = [[UIView alloc] init];
    [self.view addSubview:_m1_certificationView];
    
    [_m1_certificationView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.m1_icon.mas_bottom).offset(49);
        make.centerX.equalTo(self.view.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(SCREENWIDTH, 325));
    }];
    
    UILabel *title = [[UILabel alloc] init];
    title.text = @[@"实名信息", @"学历信息", @"房产信息", @"汽车信息"][self.m1_type];
    title.textColor = m1_color(0xFFFFFF);
    title.font = m1_font(25);
    [_m1_certificationView addSubview:title];
    
    [title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);
        make.centerX.equalTo(self.m1_certificationView.mas_centerX);
    }];
    
    NSString *house;
    if ([[M1User user].basic.house_info.number integerValue] == 0) {
        house = [M1User user].basic.house_info.title;
    }else{
        house = [NSString stringWithFormat:@"已购%@套房\n%@", [M1User user].basic.house_info.number, [M1User user].basic.house_info.house_abode];
    }
    
    NSString *car;
    
    if ([[M1User user].basic.car_info.number integerValue] == 0) {
        car = [M1User user].basic.car_info.title;
    }else{
        car = [NSString stringWithFormat:@"已购%@辆车\n%@", [M1User user].basic.car_info.number, [M1User user].basic.car_info.car_brand];
    }
    
    NSString *text = @[[NSString stringWithFormat:@"%@\n%@", [M1User user].basic.identity_info.name, [M1User user].basic.identity_info.card],
                       [NSString stringWithFormat:@"%@\n%@", [M1User user].basic.education_info.school, [M1User user].basic.education_info.desc],
                       house,
                       car][self.m1_type];
    
    
    UILabel *content = [[UILabel alloc] init];
    content.text = text;
    content.textColor = m1_color(0xFFFFFF);
    content.font = m1_font(25);
    content.textAlignment = NSTextAlignmentCenter;
    content.numberOfLines = 0;
    [_m1_certificationView addSubview:content];
    
    [content mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(title.mas_bottom).offset(45);
        make.left.offset(50);
        make.right.offset(-50);
    }];
    
    UILabel *label = [[UILabel alloc] init];
    label.text = @[@"成功完善实名信息", @"成功完善学历信息", @"成功完善房产信息", @"成功完善汽车信息"][self.m1_type];
    label.textColor = m1_color(0x999999);
    label.font = m1_font(16);
    [_m1_certificationView addSubview:label];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.m1_certificationView.mas_centerX);
        make.top.equalTo(content.mas_bottom).offset(35);
    }];
    
    UILabel *label1 = [[UILabel alloc] init];
    label1.text = [self m1_timeStamp:@[[M1User user].basic.identity_info.identity_auth.auth_time, [M1User user].basic.education_info.education_auth.auth_time, [M1User user].basic.house_info.house_auth.auth_time, [M1User user].basic.car_info.car_auth.auth_time][self.m1_type]];
    label1.textColor = m1_color(0x999999);
    label1.font = m1_font(16);
    [_m1_certificationView addSubview:label1];
    
    [label1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.m1_certificationView.mas_centerX);
        make.top.equalTo(label.mas_bottom).offset(11);
    }];
    
    if (self.m1_type != 0) {
        UIButton *cerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        cerBtn.backgroundColor = m1_color(0xDBB76B);
        [cerBtn setTitle:@"修改信息" forState:UIControlStateNormal];
        [cerBtn setTitleColor:m1_color(0xFFFFFF) forState:UIControlStateNormal];
        [cerBtn addTarget:self action:@selector(m1_cerAction:) forControlEvents:UIControlEventTouchUpInside];
        cerBtn.tag = 2;
        [_m1_certificationView addSubview:cerBtn];
        
        cerBtn.layer.cornerRadius = 45 / 2;
        cerBtn.layer.masksToBounds = YES;
        
        [cerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.m1_certificationView.mas_centerX);
            make.bottom.offset(0);
            make.size.mas_equalTo(CGSizeMake(200, 45));
        }];
    }
}

- (NSString *) m1_timeStamp:(NSString *)stamp{
    NSDateFormatter *m1_dateFormatter = [[NSDateFormatter alloc] init];
    [m1_dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"Asia/Shanghai"]];
    NSDate *assignedDateVal=[NSDate dateWithTimeIntervalSince1970:[stamp integerValue]];
    [m1_dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSString *m1_dateStr = [m1_dateFormatter stringFromDate:assignedDateVal];
    NSDate * needFormatDate = [m1_dateFormatter dateFromString:m1_dateStr];
    NSString *time = [m1_dateFormatter stringFromDate:needFormatDate];
    
    return [NSString stringWithFormat:@"审核通过时间%@", time];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
